<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
    <title>Document</title>
    <script type="text/javascript">
        // 1.创建对象
        window.onload = function() {
            var user = document.getElementById('user');
            user.onblur = function() {
                var user = document.getElementById('user');
                var username = user.value;
                var pwd = document.getElementById('passw').value;
                // console.log(username);
                var xhr = null;
                if (window.XMLHttpRequest) {
                    xhr = new XMLHttpRequest()
                } else {
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                }

                // 2准备发送
                var parm = 'user=' + username + "&password=" + pwd;
                // 解决ie浏览器乱码的问题  encodeURI()用来对中文参数进行编码，防止乱码
                xhr.open('get', './work1.php?' + encodeURI(parm));
                // 3执行发送
                xhr.send(null);
                // 4.执行回调函数
                xhr.onreadystatechange = function() {
                    if (xhr.readyState == 4) {
                        if (xhr.status == 200) {
                            // alert("hello");
                            // alert(xhr.responseText)
                            var span = document.getElementById('ineruser');
                            span.innerHTML = xhr.responseText
                        }
                    }

                }
            }
        }
    </script>
</head>

<body>
    <form action="">
        <div>用户名：
            <input type="text" name="username" id="user">
            <span id="ineruser"></span>
        </div>
        <div>密码：
            <input type="text" name="password" id="passw">
        </div>
        <input type="submit" value="注册" id="btn">
    </form>
</body>

</html>